/*
* Copyright (C) 2020 ~ 2024 chaigec All Rights Reserved.
*
* Author:     chaigec <chaigec@163.com>
* Maintainer: chaigec <chaigec@163.com>

 * Use of this source code is governed by MIT license that can be found in the
 * LICENSE file in the root of the source tree. All contributing project authors
 * may be found in the AUTHORS file in the root of the source tree.
*/

#include "MkEvent/MkTimer.h"
#include <gtest/gtest.h>

TEST(MkTimer, TimerTest)
{
    CMkTimer Timer;
    Uint32 ErrorCode = NoneError;
    ErrorCode = Timer.StartTimerThread();
    EXPECT_EQ(ErrorCode, NoneError);
    MkString DelayerSession = "123";
    MkString TimerSession = "124";
    ErrorCode = Timer.AddDelayer([]() {
    }, 10, DelayerSession);
    EXPECT_EQ(ErrorCode, NoneError);
    ErrorCode = Timer.AddTimer([]() {
    }, 10, TimerSession);
    EXPECT_EQ(ErrorCode, NoneError);
    ErrorCode = Timer.ChangeDelayerDelayTime(DelayerSession, 0);
    EXPECT_EQ(ErrorCode, NoneError);
    ErrorCode = Timer.DeleteDelayer(DelayerSession);
    EXPECT_EQ(ErrorCode, NoneError);
    ErrorCode = Timer.ChangeTimerInterval(TimerSession, 0);
    EXPECT_EQ(ErrorCode, NoneError);
    ErrorCode = Timer.DeleteTimer(TimerSession);
    EXPECT_EQ(ErrorCode, NoneError);
    ErrorCode = Timer.DeleteDelayer(DelayerSession + "1");
    EXPECT_NE(ErrorCode, NoneError);
    ErrorCode = Timer.DeleteTimer(TimerSession + "1");
    EXPECT_NE(ErrorCode, NoneError);
    ErrorCode = Timer.AddDelayer(nullptr, 0, TimerSession);
    EXPECT_NE(ErrorCode, NoneError);

    ErrorCode = Timer.AddTimer(nullptr, 0, TimerSession);
    EXPECT_NE(ErrorCode, NoneError);

    DelayerSession.clear();
    TimerSession.clear();
    ErrorCode = Timer.AddDelayer([]() {
    }, 10, DelayerSession);
    EXPECT_EQ(ErrorCode, NoneError);
    ErrorCode = Timer.AddTimer([]() {
    }, 10, TimerSession);
    EXPECT_EQ(ErrorCode, NoneError);
    ErrorCode = Timer.ActiveDelayer(DelayerSession);
    EXPECT_EQ(ErrorCode, NoneError);
    ErrorCode = Timer.ActiveTimer(TimerSession);
    EXPECT_EQ(ErrorCode, NoneError);
    Timer.GetScore();
    ErrorCode = Timer.StopTimerThread();
    EXPECT_EQ(ErrorCode, NoneError);
}